package cn.gok.qqclient.controllers;


import cn.gok.qqclient.beans.User;
import cn.gok.qqclient.services.UserService;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class UserController {

@Autowired
private UserService userService;

@RequestMapping("/getUsers")
    public String getUsers(){
    List<User> allUsers = userService.getAllUsers();
    return JSON.toJSONString(allUsers);
}

@RequestMapping("/login")
    public  String login(HttpServletRequest request){
    String username = request.getParameter("username");
    String password = request.getParameter("password");
//    System.out.println(username+" "+password);
    Map map=new HashMap();
    if (username.equals("admin")&&password.equals("123")){
        map.put("type",1);
    }else{
        map.put("type",0);
    }

    return JSON.toJSONString(map);
}


}
